﻿@{
    ViewBag.Title = "联系单管理";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
@using LeSoft.Application.Code;
<script>
    var _state = "";
    var _psallname = "";
    var _organizeid = "@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId";
    $(function () {
        InitialPage();
        GetTree1();
        GetTree2();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height()  - 135.5);
            }, 200);
            e.stopPropagation();
        });

        //绑定组织机构
        $("#Organize").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            height: "250px",
            click: function (item) {
                if (_organizeid != item.id) {
                    _organizeid = item.id;
                    GetTree2();
                    _psallname = item.text;
                    SearchEvent();
                }
            }
        });
        $("#Organize").ComboBoxTreeSetValue(_organizeid);

        //时间
        $("#time_horizon").ComboBox({
            data: [{ "key": 2, "value": "上周" }, { "key": 1, "value": "本周" }, { "key": 4, "value": "上月" }, { "key": 3, "value": "本月" }, { "key": 5, "value": "本年" }],
            id: "key",
            text: "value",
            //description: "==请选择==",
            click: function (item) {
                var value = item.attr('data-value');
                switch (value) {
                    case "1"://本周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        break;
                    case "2"://上周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        break;
                    case "3"://本月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day + 1).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd")");
                        break;
                    case "4"://上月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day + 1).AddMonths(-1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "5"://本年
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.DayOfYear + 1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(12 - DateTime.Now.Month + 1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    default:
                        break;
                }
                $("#SelectedStartTime").html($("#StartTime").val());
                $("#SelectedEndTime").html($("#EndTime").val());
                SearchEvent();
            }
        });
        $("#time_horizon").ComboBoxSetValue(3);
        //SourceType来源类别
        $("#SourceType").ComboBox({
            data: [{ "key": 6, "value": "微信公众号" },{ "key": 5, "value": "员工APP" },{ "key": 0, "value": "其他" },{ "key": 1, "value": "内部协调" }, { "key": 2, "value": "来电" }, { "key": 3, "value": "来访" }, { "key": 4, "value": "社区APP" }],
            id: "key",
            text: "value",
            description: "==请选择=="
        });
        //BillType业务类别
        $("#BillType").ComboBox({
            data: [{ "key": 1, "value": "报修" }, { "key": 2, "value": "报事" }, { "key": 3, "value": "投诉" }, { "key": 4, "value": "建议" }, { "key": 5, "value": "表扬" }, { "key": 6, "value": "咨询" }, { "key": 7, "value": "其他" }],
            id: "key",
            text: "value",
            description: "==请选择=="
        });
     
      
    }
    function GetTree1() {
        var queryJson = $("#filter-form").GetWebControls();
        //queryJson["State"] = _state;
        queryJson["PSAllName"] = _psallname;
        queryJson["OrganizeId"] = _organizeid;
        queryJson["SourceType"] = $('#SourceType').attr('data-value');
        queryJson["BillType"] = $('#BillType').attr('data-value');
        var item = {
            url: "../../PropertyManage/CS_LinkBill/GetStateTreeList?queryJson="+JSON.stringify(queryJson),          
            onnodeclick: function (item) {
                _state = item.id;
                SearchEvent();
            }
        };
        //初始化
        $("#itemTree1").treeview(item);
    }
    function GetTree2() {
        var item = {
            url: "../../ResourceManage/RS_PStructs/GetTreeJson?IsSubstep=true&type=5&organizeid=" + _organizeid,
            onnodeclick: function (item) {
                _psallname = item.text;
                SearchEvent();
            }
        };
        //初始化
        $("#itemTree2").treeview(item);
    }
    function GetGrid() {
        var queryJson = $("#filter-form").GetWebControls();
        queryJson["State"] = _state;
        queryJson["PSAllName"] = _psallname;
        queryJson["OrganizeId"] = _organizeid;
        var $gridTable = $("#gridTable");
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_LinkBill/GetPageListJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 144.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", hidden: true },
                { label: "单据编号", name: "Code", index: "Code", width: 120, align: "center" },
                {
                    label: "单据时间", name: "Date", index: "Date", width: 120, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return formatDate(cellvalue, 'yyyy-MM-dd hh:mm:ss');
                    }
                },
                { label: "联系内容", name: "LinkContent", index: "LinkContent", width: 150, align: "left" },
                { label: "联系人", name: "LinkMan", index: "LinkMan", width: 70, align: "center" },
                { label: "联系方式", name: "LinkPhone", index: "LinkPhone", width: 100, align: "center" },
                {
                    label: "单据状态", name: "State", index: "State", width: 70, align: "center",
                    formatter: function (cellvalue, options, rowObject) {                      
                        switch (cellvalue) {
                            case 1: return "<span class=\"label label-success\">未处理</span>"; break;
                            case 2: return "<span class=\"label label-danger\">跟进中</span>"; break;
                            case 3: return "<span class=\"label label-success\">已完成未回访</span>"; break;
                            case 4: return "<span class=\"label label-danger\">已完成已回访</span>"; break;
                            case 5: return "<span class=\"label label-success\">已取消</span>"; break;
                            default: return ""; break;
                        }

                    }
                },
                {
                    label: "单据来源", name: "SourceType", index: "SourceType", width: 150, align: "center",
                    formatter: function (cellvalue, options, rowObject) {                        
                        switch (cellvalue) {
                            case "0": return "其他"; break;
                            case "1": return "内部协调"; break;
                            case "2": return "来电"; break;
                            case "3": return "来访"; break;
                            case "4": return "社区APP"; break;
                            case "5": return "员工APP"; break;
                            case "6": return "微信公众号"; break;
                            default: return ""; break;
                        }
                    }
                },
                 {
                     label: "业务种类", name: "BillType", index: "BillType", width: 150, align: "center",
                      formatter: function (cellvalue, options, rowObject) {
                          switch (cellvalue) {                           
                              case "1": return "报修"; break;
                              case "1": return "报事"; break;
                              case "3": return "投诉"; break;
                              case "4": return "建议"; break;
                              case "5": return "表扬"; break;
                              case "6": return "咨询"; break;
                              case "7": return "其他"; break;                             
                              default: return ""; break;
                          }
                      }
                 },
                  {
                      label: "是否转单", name: "IsTurn", index: "IsTurn", width: 70, align: "center",
                      formatter: function (cellvalue, options, rowObject) {
                          
                          if (cellvalue == 1) {
                              return "<span class=\"label label-success\">已转单</span>";
                          } else {
                              return "<span class=\"label label-danger\">未转单</span>";
                          }
                      }
                  },

                {
                    label: "期望完成时间", name: "ExpectDate", index: "SendDate", width: 150, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return formatDate(cellvalue, 'yyyy-MM-dd hh:mm:ss');
                    }
                },

                { label: "完成情况", name: "CompleteMemo", index: "CompleteMemo", width: 100, align: "left" }
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100, 500, 1000],
            pager: "#gridPager",
            sortname: 'Date desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true
        });  
        //查询点击事件
        $("#btn_Search").click(function () {
            SearchEvent();
            $(".ui-filter-text").trigger("click");
            $("#SelectedStartTime").html($("#StartTime").val());
            $("#SelectedEndTime").html($("#EndTime").val());
        });
        //重置事件
        $("#btn_Reset").click(function () {
            $("#Code").val("");
            $("#SourceType").attr('data-value', '');
            $("#BillType").attr('data-value', '');
            $("#SourceType .ui-select-text").html('');
            $("#BillType .ui-select-text").html('');
        });
    }
    //查询表格函数
    function SearchEvent() {
        var queryJson = $("#filter-form").GetWebControls();
        queryJson["State"] = _state;
        queryJson["PSAllName"] =_psallname;
        queryJson["OrganizeId"] = _organizeid;
        queryJson["SourceType"] = $('#SourceType').attr('data-value');
        queryJson["BillType"] = $('#BillType').attr('data-value');
        $("#gridTable").jqGrid('setGridParam', {
            url: "../../PropertyManage/CS_LinkBill/GetPageListJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            page: 1
        }).trigger('reloadGrid');

        GetTree1();
    }

    //新增
    function btn_add() {
        dialogOpen({
            id: "Form",
            title: '添加联系单',
            url: '/PropertyManage/CS_LinkBill/Detail',
            width: "1100px",
            height: "850px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    }
   
    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        
        if (keyValue) {
            dialogOpen({
                id: "Form",
                title: '编辑联系单',
                url: '/PropertyManage/CS_LinkBill/Detail?keyValue=' + keyValue,               
                width: "1100px",
                height: "850px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            })
        } else {
            dialogMsg('请选择需要编辑的单据！', 0);
        }
    }
 
    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                msg:"是否确定删除，相关单据也会删除？该操作将无法恢复",
                url: "../../PropertyManage/CS_LinkBill/RemoveForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的单据！', 0);
        }
    }

</script>


<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel" style="height: 35%; overflow-y: auto; ">           
            <div id="itemTree1"></div>
        </div>
        <div class="west-Panel" style="height: 61.5%; overflow-y: auto;">          
            <div id="Organize" type="select" class="ui-select"></div>
            <div id="itemTree2"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td>查询条件</td>
                            <td style="padding-left: 10px;">
                                <div class="ui-filter" style="width: 200px;">
                                    <div class="ui-filter-text">
                                        <strong id="SelectedStartTime">@DateTime.Now.AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd")</strong> 至 <strong id="SelectedEndTime">@DateTime.Now.AddDays(-DateTime.Now.Day + 1).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd")</strong>
                                    </div>
                                    <div class="ui-filter-list" style="width: 350px;">
                                        <table class="form" id="filter-form">
                                            <tr>
                                                <th class="formTitle">单据时间：</th>
                                                <td class="formValue">
                                                    <div style="float: left; width: 45%;">
                                                        <input id="StartTime"  type="text" value="@DateTime.Now.AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                    <div style="float: left; width: 10%; text-align: center;">至</div>
                                                    <div style="float: left; width: 45%;">
                                                        <input id="EndTime"  type="text" value="@DateTime.Now.AddDays(-DateTime.Now.Day + 1).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">单据编号：</td>
                                                <td class="formValue">
                                                    <input id="Code" type="text" class="form-control">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">单据来源</td>
                                                <td class="formValue">
                                                    <div id="SourceType" type="selectTree" class="ui-select">
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">业务种类：</td>
                                                <td class="formValue">
                                                    <div id="BillType" type="selectTree" class="ui-select">
                                                    </div>
                                                </td>
                                            </tr>
                                        </table>
                                        <div class="ui-filter-list-bottom">
                                            <a id="btn_Reset" class="btn btn-default">&nbsp;重&nbsp;&nbsp;置</a>
                                            <a id="btn_Search" class="btn btn-primary">&nbsp;查&nbsp;&nbsp;询</a>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td style="padding-left: 10px;">
                                <div id="time_horizon" type="selectTree" class="ui-select" style="width: 60px;"></div>
                                @*<div id="time_horizon" class="btn-group">
                                    <a class="btn btn-default active" data-value="1">本周</a>
                                    <a class="btn btn-default" data-value="2">上周</a>
                                    <a class="btn btn-default" data-value="3">本月</a>
                                    <a class="btn btn-default" data-value="4">上月</a>
                                    <a class="btn btn-default" data-value="5">本季</a>
                                    <a class="btn btn-default" data-value="6">本年</a>
                                </div>*@
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
    @*<div class="ui-layout-east">
        <div class="east-Panel" style="height: 97.5%;">        
            <div class="panel-Title">
                相关资料
            </div>
            <div class="tab-content">
                <ul class="folder-list">
                    <li>
                        <a class="check-link">查看房屋资料</a>
                    </li>
                    <li>
                        <a class="check-link">查看业户资料</a>
                    </li>
                    <li>
                        <a class="check-link">查看联系人资料</a>
                    </li>
                    <li class="hr-line-dashed" style="border-top: 1px dashed #e7eaec;    color: #ffffff;    background-color: #ffffff;    height: 1px;    margin: 5px 0;"></li>
                    <li>
                        <a class="check-link">查看财务记录</a>
                    </li>                   
                    <li>
                        <a class="check-link">查看客服记录</a>
                    </li>
                    <li>
                        <a class="check-link">查看转单记录</a>
                    </li>                    
                </ul>
            </div>
        </div>
    </div>*@
    <style>
        .nav-tabs {
            padding-top: 1px;
        }

        .folder-list li {
            padding: 15px;
        }
    </style>
</div>
